#include "TableInterface.h"

using namespace std;

TableInterface::TableInterface(string name)
{
	this->name = name;
	kits = new Kit*[3];
	for(int i = 0; i < 3; i ++)
		kits[i] = NULL;
}

// ------------------------------------------------------------------------------------
// Utility:
string TableInterface::toString() const {
	return name;
}
// ------------------------------------------------------------------------------------


// ------------------------------------------------------------------------------------
// Capacity:

bool TableInterface::isInspectorSlotAvailable() {
	if(kits[2] == NULL)
		return true;
	return false;
}

bool TableInterface::isATableSlotAvailable() {
	if(getAvailableFirstTwoTables() >= 0)
		return true;
	return false;
}

// ------------------------------------------------------------------------------------


// ------------------------------------------------------------------------------------
// Element acess:

int TableInterface::getIndexOf(Kit* k) {
	for(int i = 0; i < 3; i ++) {
		if(kits[i] == k)
			return i;
	}
	return -1;
}

Kit* TableInterface::peek(int index) {
	if(kits[index] == NULL || index < 0 || index >= 3) {
		//Throw Error();
		return NULL;
	}
	return kits[index];
}

Kit* TableInterface::remove(int index) {
	if(kits[index] == NULL || index < 0 || index >= 3) {
		//ThrowError();
		return NULL;
	} else {
		Kit* data = kits[index];
		kits[index] = NULL;
		return data;
	}
}

int TableInterface::getAvailableFirstTwoTables() {
	if(kits[0] == NULL)
		return 0;
	else if (kits[1] == NULL)
		return 1;
	else
		return -1;
}

// ------------------------------------------------------------------------------------


// ------------------------------------------------------------------------------------
// Modifiers:
void TableInterface::insert(Kit* data, int index) {
	if(kits[index] != NULL || index < 0 || index >= 3) {
		//ThrowError();
	} else if(kits[index] == NULL) {
		kits[index] = data;
	}
}
// ------------------------------------------------------------------------------------
//GUI stuff
//Chandler 
QPoint TableInterface::getTableSlotPosition(int slot)
{
	 return QPoint(0,0);
}
